#ifndef __OutputStream_hpp__
#define __OutputStream_hpp__

#include "Pointer.hpp"

namespace ge {

GE_DECLARE_CLASS( OutputStream );

//----------------------------------------------------------------------------//
// OutputStream
//----------------------------------------------------------------------------//

class OutputStream : public virtual ReferenceCounted
{
 public:

     OutputStream( const String& _name = 0 ) : m_name( _name ), m_pos( 0 )
     {
     }

     uint GetPos( void ) const
     {
          return m_pos;
     }

     void SetPos( int _pos, bool _relative = false )
     {   
          uint _old_pos = m_pos;
          if( _relative ) m_pos = m_pos + _pos;
          else m_pos = geChoose( _pos < 0, 0, (uint)_pos );
          if( _old_pos != m_pos ) _ApplyPos();
     }

     virtual void ToEnd( void ) = 0;

     virtual uint Write( const void* _src, uint _size )
     {
          uint _writed = WriteTo( m_pos, _src, _size );
          m_pos += _writed;
          return _writed;
     }
     
     virtual uint WriteTo( uint _offset, const void* _src, uint _size ) = 0;

     virtual void Flush( void ) = 0;

 protected:

     virtual ~OutputStream( void ) {}

     virtual void _ApplyPos( void ) {}

     String m_name;
     uint m_pos;
};

} // namespace ge

#endif//__OutputStream_hpp__
